import Request from "@/common/utils/request/index";
import { PageList } from "@/types/model/pageList.model";
import {
  AddSalesPaymentDTO,
  CreateSalesOrderDTO,
  GetSnsDTO,
  SearchSnsListDTO,
  SearchVariantDTO,
} from "@/types/model/sales/dtos/sales.dto";
import {
  SalesOrderDetailVO,
  SalesSearchSnVO,
  SalesSearchVariantVO,
  SNVO,
} from "@/types/model/sales/vos/sales.vo";

enum Api {
  SearchVariant = "/jeecgboot/posSales/searchVariant",
  CreateSalesOrder = "/jeecgboot/posSales/createSalesOrder",
  searchSaleSn = "/jeecgboot/posSales/searchSaleSn",
  GetSalesOrderList = "/jeecgboot/posSales/list",
  GetSalesOrderDetail = "/jeecgboot/posSales/getOrderDetail",
  AddSalesPayment = "/jeecgboot/posSales/addSalesPayment",
  SearchSnsList = "/jeecgboot/posSales/searchSnsList",
  CompleteOrder = "/jeecgboot/posSales/completeOrder",
}

export const searchVariant = (params: SearchVariantDTO) => {
  return Request.getInstance().send<PageList<SalesSearchVariantVO>>({
    url: Api.SearchVariant,
    method: "GET",
    params,
  });
};

export const createSalesOrder = (params: CreateSalesOrderDTO) => {
  return Request.getInstance().send<string>({
    url: Api.CreateSalesOrder,
    method: "POST",
    data: params,
  });
};

export const searchSaleSn = (params: GetSnsDTO) => {
  return Request.getInstance().send<PageList<SNVO>>({
    url: Api.searchSaleSn,
    method: "GET",
    params,
  });
};

export const getSalesOrderList = (params: any) => {
  return Request.getInstance().send({
    url: Api.GetSalesOrderList,
    method: "GET",
    params,
  });
};

export const getSalesOrderDetail = (orderId: string) => {
  return Request.getInstance().send<SalesOrderDetailVO>({
    url: Api.GetSalesOrderDetail,
    method: "GET",
    params: {
      id: orderId,
    },
  });
};

export const addSalesPayment = (params: AddSalesPaymentDTO) => {
  return Request.getInstance().send<string>({
    url: Api.AddSalesPayment,
    method: "POST",
    data: params,
  });
};

export const searchSnsList = (params: SearchSnsListDTO) => {
  return Request.getInstance().send<PageList<SalesSearchSnVO>>({
    url: Api.SearchSnsList,
    method: "GET",
    params,
  });
};

export const completeOrder = (orderId: string) => {
  return Request.getInstance().send<void>({
    url: Api.CompleteOrder,
    method: "POST",
    data: {
      orderId,
    },
  });
};
